package com.boxuegu.myapplication.view;

import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ListView;


import com.boxuegu.myapplication.R;
import com.boxuegu.myapplication.adapter.CourseAdapter;
import com.boxuegu.myapplication.bean.CourseBean;

import java.util.ArrayList;
import java.util.List;

public class CourseView {
    private View view;
    private AppCompatActivity context;

    public CourseView(AppCompatActivity context){
        this.context=context;
        LayoutInflater layoutInflater=LayoutInflater.from(context);
        view=layoutInflater.inflate(R.layout.main_view_course,null);
        initView();
    }

    private void initView(){
        FrameLayout fl_adbanner=view.findViewById(R.id.fl_adbanner);
        //生成广告内容，传给广告栏对象
        int adsId[]={R.drawable.banner_1,R.drawable.banner_2,R.drawable.banner_3};
        MyAdBanner myAdBanner=new MyAdBanner(context,adsId);
        fl_adbanner.addView(myAdBanner.getView());

        ListView listView=view.findViewById(R.id.lv_list);

        List<CourseBean> beans=new ArrayList<CourseBean>();
        CourseBean bean=new CourseBean();
        bean.id=1;
        bean.iconId=R.drawable.banner_1;
        bean.imgTitle="123";
        bean.title="第1章";
        bean.intro="Anroid入门";
        beans.add(bean);

        bean=new CourseBean();
        bean.id=2;
        bean.iconId=R.drawable.banner_2;
        bean.imgTitle="123";
        bean.title="第2章";
        bean.intro="Activity";
        beans.add(bean);

        bean=new CourseBean();
        bean.id=3;
        bean.iconId=R.drawable.banner_3;
        bean.imgTitle="123";
        bean.title="第3章";
        bean.intro="Intent";
        beans.add(bean);

//        bean=new CourseBean();
//        bean.id=4;
//        bean.iconId=R.drawable.banner_1;
//        bean.imgTitle="123";
//        bean.title="第4章";
//        beans.add(bean);

        CourseAdapter adapter=new CourseAdapter(context,beans);
        listView.setAdapter(adapter);
    }

    public View getView() {
        return view;
    }
}
